import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:ums_pay/model/models.dart';

import 'ums_pay_platform_interface.dart';

/// An implementation of [UmsPayPlatform] that uses method channels.
class MethodChannelUmsPay extends UmsPayPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('ums_pay');

  @override
  Future<String?> getPlatformVersion() async {
    final version =
        await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  Future<UmsPayResponseResult?> pay(String channel, String data) async {
    final result = await methodChannel.invokeMethod<Map<dynamic, dynamic>>(
        'pay', {'channel': channel, 'data': data});
    return UmsPayResponseResult(
        code: result?['code'], msg: result?['msg'], data: result?['data']);
  }
}
